namespace SimpleWebServices.Net.Mail
{
    using System;
    using System.Collections.Specialized;
    using System.Net.Mail;
    using System.Web;
    using System.Web.Mvc;
    using Moq;
    using SimpleWebServices;
    using Xunit;

    public sealed class InternalServerErrorMailMessageFacts
    {
        [Fact]
        public void typedef()
        {
            Assert.True(new ObjectExpectations<InternalServerErrorMailMessage>()
                .DerivesFrom<MailMessage>()
                .IsConcreteClass()
                .IsSealed()
                .NoDefaultConstructor()
                .Result);
        }

        [Fact]
        public void ctor_ExceptionContext()
        {
            ExceptionContext filterContext = new ExceptionContext
            {
                HttpContext = new Mock<HttpContextBase>().Object,
                Exception = new HttpException(),
                ExceptionHandled = false
            };

            Assert.NotNull(new InternalServerErrorMailMessage(filterContext));
        }

        [Fact]
        public void ctor_ExceptionContextNull()
        {
            Assert.Throws<ArgumentNullException>(() => new InternalServerErrorMailMessage(null as ExceptionContext));
        }

        [Fact]
        public void op_Send()
        {
            var mock = new Mock<HttpContextBase>();
            mock.SetupGet<string>(x => x.Request.HttpMethod).Returns("GET").Verifiable();
            mock.SetupGet<Uri>(x => x.Request.Url).Returns(new Uri("http://example.com/path?query")).Verifiable();
            mock.SetupGet<NameValueCollection>(x => x.Request.Headers).Returns(new NameValueCollection { { "Accept", "*/*" } }).Verifiable();

            ExceptionContext filterContext = new ExceptionContext
            {
                HttpContext = mock.Object,
                Exception = new HttpException(),
                ExceptionHandled = false
            };

            new InternalServerErrorMailMessage(filterContext).Send();

            mock.VerifyAll();
        }
    }
}